//
//  VisitorLoginView.swift
//  MQWeibo
//
//  Created by SYN on 15/11/12.
//  Copyright © 2015年 SYN. All rights reserved.
//

import UIKit

//协议方法
protocol visitorLoginViewDelegate:NSObjectProtocol{
    //点击注册按钮
    func visitorRegisterDidSelected()
    //点击登陆按钮
    func visitorLoginDidSelected()
}

class VisitorLoginView: UIView {

    @IBOutlet weak var smallicon: UIImageView!

    @IBOutlet weak var backColor: UIImageView!
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var messageLable: UILabel!
    
    //定义代理
    weak var delegate: visitorLoginViewDelegate?
    
    //首页必须要其他页面需要
    //传递参数的时候,可以指定一个默认值,不需要到处修改代码
    func setupInfo(imageName: String, message: String, isHome: Bool = false){
        
        iconView.hidden = !isHome
        
        if isHome {
            
            print( "开始",smallicon.layer.animationForKey("rotationAnim"))
            
            iconView.image = UIImage(named: imageName)
            
            startAnimation()
            
        }else{
            backColor.hidden = true
            
            smallicon.image = UIImage(named: imageName)
            
        }
        
        messageLable.text = message
        
//        isHome ? startAnimation() : stopAnimation()
        
    }
    /**
    开始动画
    */
    func startAnimation(){
        print(__FUNCTION__)
        
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.toValue = 2 * M_PI
        
        anim.repeatCount = MAXFLOAT
        
        anim.duration = 20.0
        
        smallicon.layer.addAnimation(anim, forKey: "rotationAnim")
    }
    /**
    停止动画
    */
//    func stopAnimation(){
//        print(__FUNCTION__)
//        
//        smallicon.layer.removeAllAnimations()
//        
//    }
//    
    
    @IBAction func register() {
        delegate?.visitorRegisterDidSelected()
    }
    
    @IBAction func login() {
        delegate?.visitorLoginDidSelected()
    }
}
